<?php
    //用户登录
    require '../db.php';

    $username = $_GET["ADM"];
    $password = $_GET["PW"];

    $conn = connect("bcoh");

    $result = select($conn, "users", "Password, Email", "UserName='$username'");

    if (mysqli_num_rows($result) == 1 && (!strcmp($password, ($ret = mysqli_fetch_assoc($result))["Password"]))) {
        if (count(explode('@', $ret['Email'])) == 3)
            echo "Error 0x02"; //账号邮箱未验证
        else {
            echo "Success $username ";
            
            $username = md5($username);
            $imgs=array(".jpg", "jpeg", "png", "tiff", "gif");
        
            foreach ($imgs as &$img){
                $file = $username . $img;
        
                if(file_exists("../../img/users/" . $file)) {
                    echo "/img/users/" . $file;
                    return;
                }
            }
        
            echo "/img/users/default.jpg";
        }
    } else
        echo "Error 0x01"; //未注册账号

    close($conn);
?>